home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / AppleTalk Wide Area / XTI Shell Sample Code / XTIShellADev.c < prev   
Encoding:
C/C++ Source or Header  |  1993-02-15  |  11.2 KB  |  439 lines  |  [TEXT/MPS ]

  1. /*_________________________________________________________________________________
  2.  
  3.     XTIShellADev.c
  4.     
  5.     Apple Computer, Inc. 
  6.     Copyright (C) 1992,1993.  All rights reserved.
  7.     
  8.     Main C code for user interface portion of the XTI Shell adev.  This file is
  9.     really meant to be a shell in the truest sense of the word.  There is not a 
  10.     lot of code here, except for the MGetADev routine, but more just place holders 
  11.     for your interface code.
  12.     
  13.     Revision History:
  14.  
  15. __________________________________________________________________________________*/
  16.  
  17. #include    "XTIShell.h"
  18.  
  19. /* ___ Defines ___ */
  20. //
  21. // Fill in the height of your interface window here 
  22. //
  23. #define        kXTIWindHeight            200            
  24.  
  25.  
  26. /* ___ MGetAdev Locals (must be 8 bytes)___ */
  27. typedef struct XTIMGetLocals {
  28.     short            devInd;
  29.     Boolean            onlySlot;
  30.     char            filler;
  31.     short            mask;
  32.     char            nextPort;
  33.     char            nextSlot;
  34. } XTIMGetLocals, *XTIMGetLocalsPtr;
  35.  
  36. /*______________________________________________________________________________
  37.     MGetADEV
  38.     
  39.     This routine gets method based ADEV port information.  It currently will 
  40.     bring up the XTI Shell icon under the modem and printer ports.  It must be 
  41.     modified to display a method icon under the appropriate device for your link.
  42.   
  43.     Returns:    status, 0 for valid information ,1 for no more information or 
  44.                 error.
  45.                  
  46.     Parameters:    <-> aRecPtr        ADev record pointer
  47.     
  48.     Note:        If adev signature size is 0, then first time.        
  49.                 adevLocals use XTIMGetLocals struct.
  50. ______________________________________________________________________________*/
  51.  
  52. #define        kPrinterDev            1        /* 4th byte of signature, device/slot */
  53. #define        kModemDev            2
  54.  
  55. char MGetADEV(TAdevRecPtr    aRecPtr)
  56. {
  57.     register    TAdevItemPtr        myItemPtr;
  58.     register    XTIMGetLocalsPtr    rtLocPtr = (XTIMGetLocalsPtr)aRecPtr->adevLocals;
  59.                 Handle                tempIconHdl,
  60.                                     tempStrHdl;
  61.                 short                iconResId,
  62.                                     strResId;
  63.                 char                thisPort,
  64.                                     thisSlot;
  65.                 char                returnVal = noErr;
  66.  
  67.     if (!aRecPtr->adevID.aidSize) {
  68.         rtLocPtr->devInd = 0;                                /* so that first one is modem */
  69.         rtLocPtr->onlySlot = false;
  70.     }
  71.     
  72.     /* fill ADevRec with port information */
  73.     /* ___ Port/Slot Counter (device indicator)___ */
  74.     rtLocPtr->devInd++;
  75.  
  76.     /* ___ Device ___ */
  77.     myItemPtr = &aRecPtr->adevDevice;
  78.     myItemPtr->itemFlags = 0;
  79.     switch (rtLocPtr->devInd) {
  80.         case kModemDev:                                                        /* MODEM PORT */                
  81.             myItemPtr->itemRef = kBuiltInRef | kModemPort;
  82.             iconResId = kModemIconRes;
  83.             strResId = kModemStrRes;
  84.             myItemPtr->itemFlags |= kExclusFlagMask;            /* Modem port is used exclusively */
  85.             break;
  86.         case kPrinterDev:                                        /* PRINTER PORT */
  87.             myItemPtr->itemRef = kBuiltInRef | kPrinterPort;
  88.             iconResId = kPrinterIconRes;
  89.             strResId = kPrintStrRes;
  90.             myItemPtr->itemFlags |= kExclusFlagMask;            /* Printer port is used exclusively */
  91.             break;
  92.         default:                                                
  93.             returnVal = kMGetNoMore;
  94.             goto mGetADEVEx;
  95.             break;
  96.     }
  97.     tempIconHdl = Get1Resource( 'ICON', iconResId );
  98.     if (ResError() || !tempIconHdl) {
  99.         returnVal = kMFatalErr;                    
  100.         goto mGetADEVEx;
  101.     }
  102.     tempStrHdl = Get1Resource( 'STR ', strResId );
  103.     if (ResError() || !tempStrHdl) {
  104.         returnVal = kMFatalErr;                
  105.         goto mGetADEVEx;
  106.     }
  107.  
  108.     myItemPtr->itemIcon = tempIconHdl;
  109.     myItemPtr->itemStr = (StringHandle)tempStrHdl;
  110.     myItemPtr->itemFlags |= kInfoFlagMask;
  111.         
  112.     /* ___ Port ___ */
  113.     myItemPtr = &aRecPtr->adevPort;
  114.     myItemPtr->itemFlags = 0;
  115.     switch (rtLocPtr->devInd) {
  116.         case kModemDev:
  117.             thisPort = 0;
  118.             thisSlot = kModemPort;
  119.             break;
  120.         case kPrinterDev:
  121.             thisPort = 0;
  122.             thisSlot = kPrinterPort;
  123.             break;
  124.         default:
  125.             break;
  126.     }
  127.     myItemPtr->itemIcon = tempIconHdl;                    
  128.     myItemPtr->itemStr = (StringHandle)tempStrHdl;
  129.     
  130.     
  131.     /* ___ Method ___ */
  132.     myItemPtr = &aRecPtr->adevMethod;
  133.     myItemPtr->itemFlags = 0;
  134.     myItemPtr->itemRef = kXTIShellRef;
  135.     tempIconHdl = Get1Resource( 'ICON', kRemoteIconRes );
  136.     if (ResError() || !tempIconHdl) {
  137.         returnVal = kMGetNoMore;    
  138.         goto mGetADEVEx;
  139.     }
  140.     myItemPtr->itemIcon = tempIconHdl;
  141.     tempStrHdl = Get1Resource( 'STR ', kRemoteStrRes );
  142.     if (ResError() || !tempStrHdl) {
  143.         returnVal = kMGetNoMore;            
  144.         goto mGetADEVEx;
  145.     }
  146.     myItemPtr->itemStr = (StringHandle)tempStrHdl;
  147.     myItemPtr->itemFlags = kInfoFlagMask;
  148.     
  149.     /* ___ Adev ID ___ */
  150.     aRecPtr->adevID.aidSize = 1;                                        /* number of longs */
  151.     ((TADEVSigRecPtr)(aRecPtr->adevID.aidData))->id = 'XX';
  152.     ((TADEVSigRecPtr)(aRecPtr->adevID.aidData))->port = thisPort;
  153.     ((TADEVSigRecPtr)(aRecPtr->adevID.aidData))->slot = thisSlot;
  154.     
  155.     
  156. mGetADEVEx:    
  157.     return( returnVal );
  158.  
  159. }
  160.  
  161. /*______________________________________________________________________________
  162.     MAGetAttribs - Get attributes of window to determine the height necesary.    
  163.     
  164.     Returns:     status, 0 for no err, -1 for insufficient drawing height
  165.     
  166.     Parameters:    <-> awPtr        ADev window pointer
  167.     
  168. ______________________________________________________________________________*/
  169.  
  170.  
  171. char MAGetAttribs(TAdevWindPtr    awPtr)
  172.  
  173. {
  174.     char    returnVal = noErr;
  175.     
  176.     if (awPtr->awRect.bottom < kXTIWindHeight) {
  177.         returnVal = kMInsufDrawHt;
  178.     }
  179.     else {
  180.         awPtr->awRect.bottom = kXTIWindHeight;        /* window height */
  181.         awPtr->awMessage = kXTIMinBufSize;            /* min buf size */
  182.     }
  183.     
  184.     return( returnVal );
  185.  
  186. }
  187.  
  188. /*______________________________________________________________________________
  189.     XTIINIT - Initialize local variables in preparation for editing.    
  190.     
  191.     Returns:     status, 0 for no err, -1 for initialization error
  192.     
  193.     Parameters:    <-> awPtr        ADev window pointer
  194.     
  195. ______________________________________________________________________________*/
  196.  
  197. char MAInit(TAdevWindPtr    awPtr)
  198.  
  199. {    
  200.  
  201. //
  202. // This is the routine where you should do things like creating Text Edit
  203. // boxes, radio buttons, etc.  Set these things to their initial values
  204. // based on the values in the awConfig record passed in.
  205. //
  206.     return( noErr );
  207. }
  208.  
  209.  
  210. /*______________________________________________________________________________
  211.     MAKill - Dispose local variables and terminate editing of config data        
  212.  
  213.     Returns:     status, 0 for no err, -1 for can't close right now
  214.     
  215.     Parameters:    <-> awPtr        ADev window pointer
  216.     
  217. ______________________________________________________________________________*/
  218.  
  219. char MAKill(TAdevWindPtr    awPtr)
  220.  
  221. {    
  222. //
  223. // Dispose of any memory allocated.
  224. //
  225.     return( noErr );
  226. }
  227.  
  228. /*______________________________________________________________________________
  229.     MAActivate - Perform activation/deactivation for the Port Info window.    Handle
  230.                  special case of router active or not.    
  231.  
  232.     Returns:     status, 0 for no err,-1 for fatal err
  233.     
  234.     Parameters:    <-> awPtr        ADev window pointer
  235.     
  236.     Note:        The text edit should be active with an activate event and if the router is not
  237.                 running.
  238.     
  239. ______________________________________________________________________________*/
  240.  
  241. char MAActivate(TAdevWindPtr    awPtr)
  242.  
  243. {
  244. //
  245. // Do whatever needs to be done to activate or deactivate your window.
  246. //
  247.  
  248.     return( noErr );
  249. }
  250.  
  251.  
  252. /*______________________________________________________________________________
  253.     MAClick - Called whenever a mousedown occurs in the port's drawing area,    
  254.               this routine determines if any further action is required.                    
  255.  
  256.      Returns:     status, 0 for no err,-1 for fatal err
  257.     
  258.     Parameters:    <-> awPtr        ADev window pointer
  259.     
  260. ______________________________________________________________________________*/
  261.  
  262. char MAClick(TAdevWindPtr    awPtr)
  263. {
  264. //
  265. // Process the mouse click. 
  266. //
  267.     return ( noErr );
  268. }
  269.  
  270. /*______________________________________________________________________________
  271.     MADraw - Draw the contents the port editing rect, except for controls.         
  272.              All controls are drawn by the calling routine.                                
  273.     
  274.      Returns:     status, 0 for no err,-1 for fatal err
  275.     
  276.     Parameters:    <-> awPtr        ADev window pointer
  277.     
  278.     Note:        Handle special case of router active
  279.     
  280. ______________________________________________________________________________*/
  281.  
  282.  
  283. char MADraw(TAdevWindPtr    awPtr)
  284. {
  285. //
  286. // Draw the window.  If the router is running, configuration items should be 
  287. // grayed out so the user does not think they can be modified.
  288. //
  289.     return( noErr );
  290. }
  291.  
  292. /*______________________________________________________________________________
  293.     MAMessage - Edit the contents of text edit field, if any, and
  294.                 change router status
  295.  
  296.      Returns:     status, 0 for no err, -1 for fatal err
  297.     
  298.     Parameters:    <-> awPtr        ADev window pointer
  299.     
  300. ______________________________________________________________________________*/
  301.  
  302. char MAMessage(TAdevWindPtr    awPtr)
  303. {
  304. //
  305. // Respond to the following messages:
  306. //
  307.     switch (awPtr->awMessage) {
  308.         case kUndoEvt:
  309. //
  310. // Process the undo for the current text edit.
  311. //
  312.         case kCutEvt:
  313.             break;
  314. //
  315. // Process the cut for the current text edit.
  316. //
  317.             break;
  318.         case kCopyEvt:
  319. //
  320. // Process the copy for the current text edit.
  321. //
  322.             break;
  323.         case kPasteEvt:
  324. //
  325. // Process the paste for the current text edit.
  326. //
  327.             break;
  328.         case kClearEvt:
  329. //
  330. // Process the clear for the current text edit.
  331. //
  332.             break;
  333.         case kRouterInact:
  334. //
  335. // Process the router inactivate event.
  336. //
  337.             break;
  338.         case kRouterAct:
  339. //
  340. // Process the router activate event.
  341. //
  342.             break;
  343.     }
  344.  
  345.     return( noErr );
  346. }
  347.  
  348. /*______________________________________________________________________________
  349.     MAIdle - Update the window if no other event (Call TEIdle)                    
  350.  
  351.      Returns:     status, 0 for no err,-1 for fatal err
  352.     
  353.     Parameters:    <-> awPtr        ADev window pointer
  354.     
  355. ______________________________________________________________________________*/
  356.  
  357. char MAIdle(TAdevWindPtr    awPtr)
  358. {
  359. //
  360. // Process an idle event for the window.
  361. // 
  362.     return( noErr );
  363. }
  364.  
  365. /*______________________________________________________________________________
  366.     MAKey - Process a key-down event if you have an active TextEdit field                    
  367.     
  368.      Returns:     status, 0 for no err,-1 for fatal err
  369.     
  370.     Parameters:    <-> awPtr        ADev window pointer
  371.     
  372.     Note:         Password text edit box actually is two boxes mirrored.
  373. ______________________________________________________________________________*/
  374.  
  375.  
  376. char MAKey(TAdevWindPtr    awPtr)
  377. {
  378. //
  379. // Process a key event in your window.
  380. //
  381.     return( noErr );
  382. }
  383.  
  384.  
  385. /*______________________________________________________________________________
  386.     MASelectTE - Activate the TextEdit field indicated                                
  387.     
  388.      Returns:     status, 0 for no err,-1 for cannot deactiv the current TE field
  389.     
  390.     Parameters:    <-> awPtr        ADev window pointer
  391.     
  392. ______________________________________________________________________________*/
  393.  
  394.  
  395. char MASelectTE(TAdevWindPtr    awPtr)
  396. {
  397. //
  398. // Deactivate the current text edit and activate the specified one.
  399. //
  400.     return( noErr );
  401. }
  402.  
  403. /*______________________________________________________________________________
  404.     MAGetConfig - Get the current contents of the config editing fields            
  405.  
  406.      Returns:     status, 0 for no err,-1 for invalid config field data
  407.     
  408.     Parameters:    <-> awPtr        ADev window pointer
  409.     
  410. ______________________________________________________________________________*/
  411.  
  412. char MAGetConfig(TAdevWindPtr    awPtr)
  413. {    
  414. //
  415. // Fill in the awConfig record based on the user configuration
  416. //
  417.     return( noErr );
  418. }
  419.  
  420. /*______________________________________________________________________________
  421.     MAGetLine - Get a line of the current configuration    
  422.  
  423.      Returns:     status, 0 for no err,-1 for no more lines
  424.     
  425.     Parameters:    <-> awPtr        ADev window pointer
  426.     
  427. ______________________________________________________________________________*/
  428.  
  429. char MAPrint(TAdevWindPtr    awPtr)
  430. {
  431. //
  432. // Fill the summary string with one line of the current configuration.
  433. // This routine will be called repeatedly until you indicate that
  434. // there are no more lines.
  435. //
  436.     return( noErr );
  437. }
  438.  
  439.